﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>对从表指定列的自动计算</title>
    <script language="JavaScript" src="../../../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=AutoFullDtlField_Init&FK_MapData=" + GetQueryString("FK_MapData") + "&KeyOfEn=" + GetQueryString("KeyOfEn") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = JSON.parse(data);

                    var dtls = data["Dtls"];
                    var mapExt = data['Sys_MapExt'];
                    var mapExt = mapExt[0];

                    // 根据这个格式对下拉框设置默认值.  "ND101Dtl1.JinE.Sum";
                    var doc = mapExt.Doc;
                    var docs = doc.split('\.');

                    if (doc == "") {
                        document.getElementById("Btn_Delete").disabled = true;
                    }

                    var selectID = docs[0];
                    var field = docs[1];
                    var jsfs = docs[2];

                    GenerBindDDL("DDL_Dtl", dtls, "No", "Name", selectID);

                    $("#DDL_Dtl").on("change", function () {
                        GenerBindDDL("DDL_Field", data[$(this).val()], "No", "Name");
                    });

                    if (typeof data[selectID] != "undefined") {
                        GenerBindDDL("DDL_Field", data[selectID], "No", "Name", field);
                    } else {
                        GenerBindDDL("DDL_Field", data[dtls[0].No], "No", "Name", field);
                    }

                    //设置计算方式.
                    SetDDLVal("DDL_JSFS", jsfs);

                    //调用公共类库的方法:执行批量主表赋值.
                    // GenerFullAllCtrlsVal(mapExt);
                    return;
                }
            });

            $("#Msg").html("");
        });



        function Save() {

            $("#Msg").html("正在保存,请稍后......");

            var frmData = $("#cc").serialize();

            var myurl = Handler + "?DoType=AutoFullDtlField_Save&FK_MapData=" + GetQueryString("FK_MapData") + "&KeyOfEn=" + GetQueryString("KeyOfEn") + "&m=" + Math.random();
            $.ajax({
                data: frmData,
                type: 'post',
                async: true,
                url: myurl,
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') != -1) {

                        $("#Msg").html("<font color=red>" + data + "</font>");
                        return;
                    }


                    document.getElementById("Btn_Delete").disabled = false;


                    $("#Msg").html("<font color=green>" + data + "</font>");
                    return;
                },
                error: function (data) {
                    alert(data);
                    console.info(data);
                }
            });
        }

        function Delete() {

            if (window.confirm('您确定要删除吗？') == false)
                return false;

            // var en = new Entity("BP.Sys.MapExt");
            // en.Delete(

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=AutoFullDtlField_Delete&FK_MapData=" + GetQueryString("FK_MapData") + "&KeyOfEn=" + GetQueryString("KeyOfEn") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {
                    alert(data);
                    window.location.href = window.location.href;
                    return;
                }
            });
        }
    </script>
</head>
<body>
    <form id="cc">
    <table id="table" style="width: 100%;">
        <caption>
            对从表数值列自动计算</caption>
        <tr>
            <td colspan="3" style="width: 100%;">
                选择从表:<select id="DDL_Dtl" name="DDL_Dtl"></select>
                选择列:<select id="DDL_Field" name="DDL_Field"></select>
                选择计算方式:<select id="DDL_JSFS" name="DDL_JSFS">
                    <option value="Sum">求和</option>
                    <option value="Avg">求平均</option>
                    <option value="Max">求最大</option>
                    <option value="Min">求最小</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <input type="button" value="保存" onclick="Save()" id="Btn_Save" />
                <input type="button" value="删除" onclick="Delete()" id="Btn_Delete" />
                <a href="javascript:ShowHidden('sqlexp')">帮助:</a>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <div id='sqlexp' style='color: Gray; display: none'>
                    <ul>
                        <li>1.对从表的里，进行求和，求平均计算。 </li>
                        <li>2.当从表的对应列发生变化的时候，就调用这个规则把数据数据存储到主表里去。</li>
                        <li>3.比如：在报销表单里，费用合计是对从表的小计列求和。</li>
                        <li>4.配置信息存储格式为:Sys_MapExt的Doc 字段 ND101Dtl1.XiaoJi.Sum </li>
                        <li>
                            <img src='./Img/AutoFullDtlField.png' alt="yangshi" />
                        </li>
                    </ul>
                </div>
            </td>
        </tr>
    </table>
    <div id="Msg">
    </div>
    </form>
</body>
</html>
